package spells;

import main.Creature;
import main.Grid;
import main.RandNum;

public class IgniteMagic extends Spell{

	/**
	 * Damages the caster slightly, and restores mana in return. Also increases intelligence and consequently spell damage for a duration
	 */
	
	public IgniteMagic(){
		hasTarget = true;
		element = "Fire";
		name="Ignite Magic";
		castTime = 1;
		range=3;
		cManaChange = 1 * -2;
		healthChange = 1 * -1;
		cManaChange = 1 * 2;
		
		cIntChange = 1*2;
	}
	
	public IgniteMagic(Creature caster)
	{
		hasTarget = true;
		this.caster = caster;
		element = "fire";
		name = "Ignite Magic";
		target = caster;
		healthChange = caster.level * -1;
		cManaChange = caster.level * -2;
		
		cIntChange = caster.level*2;
	}
	
	public void setCaster(Creature c){
		caster=c;
		cManaChange=caster.level*-2;
	}//end method
	
	public String applySpell(Grid g){
		if(target!=null || !hasTarget){
			double distance;
			if(hasTarget)
				distance=g.getDToEnemy(target);
			else
				distance=0;
			if(caster.curMana+cManaChange>=0 && distance<=range){
				healthChange = caster.level * -1;
				cManaChange = caster.level * 2;
				cIntChange = caster.level*2;
				//cHealthChange = -1*(2*RandNum.randNum(1,7) + 7*caster.level);
				//do effect to target if there is a target
				if(hasTarget){
					target.curHealth+=healthChange;
					target.strength+=strChange;
					target.stamina+=stamChange;
					target.intelligence+=intChange;
					target.spirit+=spChange;
					target.curMana+=manaChange;
					if(target.curHealth<0)
						target.curHealth=0;
					if(target.curHealth>target.maxHealth)
						target.curHealth=target.maxHealth;
					if(target.curMana<0)
						target.curMana=0;
					if(target.curMana>target.maxMana)
						target.curMana=target.maxMana;
				}//end if
				
				//do effect to caster
				caster.curHealth+=cHealthChange;
				caster.strength+=cStrChange;
				caster.stamina+=cStamChange;
				caster.intelligence+=cIntChange;
				caster.spirit+=cSpChange;
				caster.curMana+=cManaChange;
				if(caster.curHealth<0)
					caster.curHealth=0;
				if(caster.curHealth>caster.maxHealth)
					caster.curHealth=caster.maxHealth;
				if(caster.curMana<0)
					caster.curMana=0;
				if(caster.curMana>caster.maxMana)
					caster.curMana=caster.maxMana;
				
				//determines what spell message to say
				if(hasTarget){
					System.out.println("reached");
					StatChange moreInt = new StatChange(5);
					moreInt.intChange = cIntChange;
					moreInt.setName("Ignited Magic");
					target.buffs.add(moreInt);
					return caster.name+" has cast "+name+ ", taking "  +healthChange+ " damage.";
				}
			}//end if
			//if you are out of range
			else if(distance>range){
				return "Out of range";
			}
			//if you are out of mana
			else{
				return "Not enough mana";
			}//end else
		}//end if
		return "";
	}//end method
	

}
